function demo
addpath([pwd,'\..'])
menu_list={
{'One Player -- random motion','ex_1',''},
{'One Player -- straight motion','ex_2',''},
{'One Player -- simple motion','ex_3',''},
{'One Player -- delta motion (delta_*_func)','ex_4',''},
{'One Player -- func_t motion (func_t)','ex_5',''},
{'One Player -- Spiral motion (step_func)','ex_6',''},
{'One Player --- van der Pol motion (ode_func) ','ex_7',''},
{'One Player -- Plane Spiral Motion','ex_8',''},
{'One Player -- Inverted Pendulum with LQR control','ex_InvPendulum','ex_InvPendulum.m'},
{'One Player -- Aircraft in Vertical Plane','ex_AircraftVP','ex_AircraftVP.m'},
{'One Player -- 2D Path Planning in Obstacle Environment','ex_PathPlanning','ex_PathPlanning.m'},
{'One Player -- Big Picture Viewer','ex_ViewImage','ex_ViewImage.m'},
{'One Player -- 3D Boring 747','ex_B747','ex_B747.m'},
{'One Player -- Linear System with Kalman filter','ex_LinSys','ex_LinSys.m'},
{'Two Players -- Missile and Target','ex_MissileTarget','ex_MissileTarget.m'},
{'Two Players -- Rock, Scissors, Paper','ex_RPS','ex_RPS.m'},
{'Two Players -- Lion and Man','ex_LionMan','ex_LionMan.m'},
{'Two Players -- Lady in Lake','ex_LadyInLake','ex_LadyInLake.m'},
{'Two Players -- Princess and Monster','ex_PrincessMonster','ex_PrincessMonster.m'},
{'Two Players -- Chess Five','ex_ChessFive','ex_ChessFive.m'},
{'Two Players -- Chess Black and White','ex_ChessBlackWhite','ex_ChessBlackWhite.m'},
{'Two Players -- PEAP Game','ex_PEAP','ex_PEAP.m'},
{'Two Players -- Aircraft Dogfight','ex_AircraftDogfight','ex_AircraftDogfight.m'},
{'Two Players -- Life Line Game','ex_LifeLineGame','ex_LifeLineGame.m'},
{'Multiple Players -- Decentralized Astrom-Wittenmark Self-Tuning Regulator','ex_MultAWSTR','ex_MultAWSTR.m'},
{'Multiple Players -- Decentralized WLS-based Adaptive Control','ex_MultWLS','ex_MultWLS.m'},
{'Multiple Players -- Decentralized Adaptive Synchronization','ex_AdapSyn','ex_AdapSyn.m'},
{'Multiple Players -- Multiple Agents Consensus','ex_MultConsensus','ex_MultConsensus.m'},
{'Multiple Players -- Multiple Robots Formation Control','ex_MultFormation','ex_MultFormation.m'},
{'Multiple Players -- Multiple Robots Target Pursuit','ex_MultPursuit','ex_MultPursuit.m'},
{'Multiple Players -- Multiple Missile Guidance','ex_MultMissile','ex_MultMissile.m'},
{'Multiple Players -- Multiple Targets Escape','ex_MultTarget','ex_MultTarget.m'}
};
m=length(menu_list);
menu_items={};
for j=1:m,
    tmp=menu_list{j};
    menu_items{j}=tmp{1};
end;
j=menu('Please choose an example',menu_items)
if j<1,
    return;
end;
disp(['Choose: ',menu_items{j}]);
tmp=menu_list{j};
feval(tmp{2});
figure(1);
winontop(1,0);
q=menu('Click OK to view the source of demo file!',{'OK','Cancel'});
if q~=1,
    return;
end;
srcfile=tmp{3};
if isempty(srcfile),
    srcfile='demo_mads.m';
end;
dos(['start tview.exe ',cd,'\',srcfile]);



%%One Player -- random motion (2D/3D)
function ex_1
space=menu('Please choose illustration space:',{'2D plane','3D space'})
if space==1,
    pos0=[0,0];ang0=0;
    ax1=[-100,100,-100,100];
else,
    pos0=[0,0,0];ang0=[0,0,0];
    ax1=[-100,100,-100,100,-100,100];
end;
P1=newplayer('pos',pos0,'ang',ang0,'motion','random','speed',20,'legend','r','plot_components',[3])
G=newgame({P1},'max_step',100,'axis',ax1,'axis2',[0,100,-100,100],'draw',2,'pause','pause;')
G=simgame(G)
keyboard

%%One Player -- straight motion
function ex_2
P1=newplayer('pos',[0,0],'ang',rand(1)*pi,'motion','straight','speed',5,'legend','b','icon',p_rect(1,1))
G=newgame({P1},'max_step',10,'axis',[-100,100,-100,100])
G=simgame(G)

%%One Player -- simple motion with movie replay
function ex_3
avi_filename='simple.avi'
motion=menu('Please choose motion type:',{'Circle Motion',' Random Simple Motion'})
if motion==1,
  fcn_delta_ang=inline('pi/100','G','P','k');
else,
  fcn_delta_ang=inline('pi/10*(rand(1)-0.6)','G','P','k');
end;
P1=newplayer('pos',[0,0],'ang',rand(1)*pi,'motion','simple','speed',100,'legend','b','icon',p_triangle(2,0,pi/6),'delta_ang_func',fcn_delta_ang)
G=newgame({P1},'max_step',300,'h',0.01,'axis',[-100,100,-100,100],'pause','pause(G.h)','moviefile',avi_filename)
G=simgame(G)
dos(['start ',avi_filename])

%%One Player -- delta motion (delta_*_func)
function ex_4
P1=newplayer('pos',[0,0],'ang',rand(1)*pi,'motion','delta','speed',10,'legend','r','icon',p_rect(1,1))
G=newgame({P1},'max_step',100,'h',0.1,'axis',[-100,100,-100,100],'delta_ang_func','delta_ang_ex4','delta_pos_func','delta_pos_ex4')
G=simgame(G)

function d_ang=delta_ang_ex4(G,P,k)
jj=mod(floor(G.step/10),2)*2-1;
d_ang=pi/2*jj;

function d_pos=delta_pos_ex4(G,P,k)
dd=[cos(P.ang),sin(P.ang)];
d_pos=dd*(G.step*0.01+G.speed);

%%One Player -- t_func motion (t_func)
function ex_5
fcn_pos_t=inline('[t,sin(t/0.1),atan2(10*cos(t/0.1),1)]')
P1=newplayer('pos',[0,0],'ang',0,'motion','func_t','speed',5,'legend','b','icon',p_triangle(2,pi,pi/6),'func_t',fcn_pos_t)
G=newgame({P1},'max_step',200,'axis',[0,2,-1.5,1.5],'h',0.01,'pause','pause;disp(G.P{1}.ang)')
G=simgame(G)


%%One Player -- Spiral motion (step_func)
function ex_6
P1=newplayer('pos',[2,0],'motion','step_func','legend','b','icon',p_circle(1),'step_func','s_spiral')
G=newgame({P1},'max_step',200,'axis',[-100,100,-100,100])
G=simgame(G)

function P=s_spiral(G,P,k)
P.ang=P.ang+0.5;
P.pos=G.step*[cos(P.ang),sin(P.ang)];


%%One Player --- van der Pol motion (ode_func)
function ex_7
P1=newplayer('pos',[2,0],'motion','ode_func','legend','r','icon',p_triangle(0.1,0,pi/6),'ode_func',@o_test)
G=newgame({P1},'max_step',200,'h',0.1,'axis',[-3,3,-3,3])
G=simgame(G)


%%One Player -- Plane Spiral Motion (t_func)
function ex_8
fcn_pos_t=inline('[t*sin(t),t*cos(t)]')
P1=newplayer('pos',[0,0],'ang',rand(1)*pi,'motion','t_func','speed',5,'legend','b','image','images/plane.bmp','img_size',5,'t_func',fcn_pos_t)
G=newgame({P1},'max_step',100,'axis',[-100,100,-100,100])
G=simgame(G)

